package myky.com.doctorapp.presenter

import io.reactivex.disposables.Disposable
import myky.com.doctorapp.R
import myky.com.doctorapp.api.ResponseTransformer
import myky.com.doctorapp.api.schedulers.SchedulerHelper
import myky.com.doctorapp.base.BasePresenterIm
import myky.com.doctorapp.base.RxSubscribe
import myky.com.doctorapp.base.SimpleSubscribe

import myky.com.doctorapp.contract.SuccessfulActivityContract
import myky.com.doctorapp.entity.DoctorEntity
import myky.com.doctorapp.model.SuccessfulActivityModel
import myky.com.doctorapp.utils.ToastUtils

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/7 on 10:22
 */
class SuccessfulActivityPresenter :BasePresenterIm<SuccessfulActivityContract.View>(), SuccessfulActivityContract.Presenter {
    override fun pEmpowerUpdate(doctorId: Int) {
        successfulActivityModel.empowerUpdate(doctorId).subscribe(object :RxSubscribe<String>(){
            override fun onSuccess(t: String) {
                mView.hideLoading()
                mView.showEmpowerUpdate(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                ToastUtils.show(mContext.resources.getString(R.string.net_exception))
            }

            override fun onSubscribe(d: Disposable) {
                mView.showLoadingView(mContext.resources.getString(R.string.empowering))
                addSubscription(d)
            }
        })
    }

    override fun getDoctorDeatails(doctorId: String, version: String) {
        successfulActivityModel.getDoctorDeatails(doctorId, version)
                .compose(ResponseTransformer.handleResult<DoctorEntity.PayLoadEntity>())
                .compose(SchedulerHelper.applySchedulers<DoctorEntity.PayLoadEntity>())
                .subscribe(object : SimpleSubscribe<DoctorEntity.PayLoadEntity>() {
                    override fun onSuccess(doctorEntity: DoctorEntity.PayLoadEntity) {
                        mView.showDoctorDeatails(doctorEntity)
                    }

                    override fun onFailed(msg: String) {
                        mView.logCat(msg)
                    }

                    override fun onSubscribe(d: Disposable) {
                        addSubscription(d)
                    }
                })
    }


    val successfulActivityModel:SuccessfulActivityModel=SuccessfulActivityModel()
    override fun pempower(doctorId: Int) {
        successfulActivityModel.empower(doctorId).subscribe(object :RxSubscribe<String>(){
            override fun onSuccess(t: String) {
                mView.showDataSuccess(t)
            }

            override fun onFailed(code: Int, msg: String?) {
            }

            override fun onSubscribe(d: Disposable) {
                addSubscription(d)
            }
        })
    }
}
